import 'package:flutter/material.dart';
import 'package:get/get.dart';
import '../controller/language_controller.dart';

class LanguageDialog extends StatelessWidget {
  final LanguageController languageController = Get.find();
  
  @override
  Widget build(BuildContext context) {
    return AlertDialog(
      backgroundColor: Color(0xFF2A2A2A),
      title: Text(
        'select_language'.tr,
        style: TextStyle(color: Colors.white),
      ),
      content: Column(
        mainAxisSize: MainAxisSize.min,
        children: languageController.supportedLanguages.keys.map((languageCode) {
          return Obx(() => RadioListTile<String>(
            title: Text(
              languageController.languageNames[languageCode]!,
              style: TextStyle(color: Colors.white),
            ),
            value: languageCode,
            groupValue: languageController.currentLanguage.value,
            onChanged: (value) {
              if (value != null) {
                languageController.changeLanguage(value);
                Get.back();
                Get.snackbar(
                  'language_changed'.tr,
                  languageController.getCurrentLanguageName(),
                  backgroundColor: Color(0xFF2A2A2A),
                  colorText: Colors.white,
                );
              }
            },
            activeColor: Colors.blue,
          ));
        }).toList(),
      ),
      actions: [
        TextButton(
          onPressed: () => Get.back(),
          child: Text(
            'cancel'.tr,
            style: TextStyle(color: Colors.grey[400]),
          ),
        ),
      ],
    );
  }
}